<template>
  <terminal :context="statusStore.currentServerName" name="my-terminal" theme="dark" @exec-cmd="onExecCmd"
    :show-header="false" />
</template>

<script setup lang="ts">
import { useStatusStore } from '@/stores'
import { Terminal, type DragConfig, type FailedFunc, type SuccessFunc, type TerminalMessageClass } from 'vue-web-terminal'
import axios from 'axios'
const statusStore = useStatusStore()
const onExecCmd = (key: string, command: string, success: SuccessFunc, failed: FailedFunc) => {
  axios.post(`/api/terminal?host=${statusStore.currentServerIP}&username=starsac&password=123&command=${command}`)
    .then(({data}) => {
      success({
        type: 'normal',
        class: data.status,
        tag: data.status,
        content: data.result
      })
    }).catch((err) => {
      failed(err.message)
    })
  // failed('Something wrong!!!')
  // let allClass = ['success', 'error', 'system', 'info', 'warning']

  // let clazz = allClass[Math.floor(Math.random() * allClass.length)];
  // success({
  //   type: 'normal',
  //   class: clazz as TerminalMessageClass,
  //   tag: clazz,
  //   content: `Your command is '${command}'`
  // })
}
</script>



<style scoped></style>
